<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up()
    {
        Schema::create('user_tokens', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('wechat_user_id');
            $table->string('token')->unique();
            $table->timestamp('expired_at');
            $table->timestamps();
        });
        
        Schema::table('user_tokens', function (Blueprint $table) {
            $table->foreign('wechat_user_id')
                  ->references('id')
                  ->on('wechat_service_account_users')
                  ->onDelete('cascade');
        });
    }

    public function down()
    {
        Schema::dropIfExists('user_tokens');
    }
};